/**
 * Alipay.com Inc. Copyright (c) 2004-2018 All Rights Reserved.
 */
package com.yeyks.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yeyks.model.PreOrderInfo;
import com.yeyks.service.OrderService;
//import com.pingplusplus.model.Event;
//import com.pingplusplus.model.Webhooks;
import com.yeyks.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.util.Enumeration;

/**
 *
 * @author Beacon
 * @version $Id: PingxxController.java, v 0.1 2018年08月27日 19:29 Beacon Exp $
 */
@RestController
@RequestMapping(value = "/pingxx")
public class PingxxController {

    @Autowired
    OrderService orderService;

//    /**
//     * 回调接口
//     * @param request
//     * @param response
//     * @throws Exception
//     */
//    @RequestMapping(value = "/payNotify", method = RequestMethod.POST)
//    public void updateValid(
//            HttpServletRequest request, HttpServletResponse response
//
//    ) throws Exception {
//
//        //获取头部所有信息
//        Enumeration headerNames = request.getHeaderNames();
//        while (headerNames.hasMoreElements()) {
//            String key = (String) headerNames.nextElement();
//            String value = request.getHeader(key);
//        }
//        // 获得 http body 内容
//        BufferedReader reader = request.getReader();
//        StringBuffer buffer = new StringBuffer();
//        String string;
//        while ((string = reader.readLine()) != null) {
//            buffer.append(string);
//        }
//        reader.close();
//
//        // 解析异步通知数据
//        Event event = Webhooks.eventParse(buffer.toString());
//
//        // 签名
//        String signature = request.getHeader("X-Pingplusplus-Signature");
//
//        if ("charge.succeeded".equals(event.getType())) {
//            // 支付成功
//            JSONObject obj = (JSONObject) JSON.parse(buffer.toString());
//            JSONObject data = (JSONObject) obj.get("data");
//            JSONObject object = (JSONObject) data.get("object");
//
//            String orderNo = object.getString("order_no");
//
//            if (!orderService.chargeSucceededOrder(orderNo)) {
//                response.setStatus(500);
//            } else {
//                response.setStatus(200);
//            }
//        }
//    }

}